package JUC.读写文件;

import org.junit.Test;

import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class 读写文件 {
    public static void main(String[] args) throws IOException {
        FileInputStream fileInputStream = new FileInputStream("C:\\Users\\Administrator\\Desktop\\ddd.txt");

        FileChannel channel = fileInputStream.getChannel();ByteBuffer byteBuffer = ByteBuffer.allocate(100);

        // read是读操作 不仅仅是判断
        while (channel.read(byteBuffer)!=-1) {
            System.out.println("再读100");
            System.out.println(new String(byteBuffer.array(), 0, byteBuffer.limit())); //Hello,Java菜鸟程序员
            byteBuffer.clear(); // 读完清空
            System.out.println("情况缓存");
        }

        channel.close();
        fileInputStream.close();
    }

}
/*

复制转移就
out.write(in);
        FileInputStream in = new FileInputStream("hello.txt");
        FileOutputStream out = new FileOutputStream("world.txt");
 */